'''
@author : xaing
@time : 2018/4/5 17:30
@地址 : 广州
@作用 : 91 的txt文件转json转excel
@结果 :
'''
import json
import csv


def write_header():
    csvfile = open('./91.csv', 'w', newline='')
    writer = csv.writer(csvfile)
    writer.writerow(["index", "title", "long", "date", "collection", "href"])


def write_csv(x, lines):
    line = lines[x]
    d = json.loads(line)
    index = d['index']
    title = d['title']
    long = d['long']
    date = d['date']
    collection = d['collection']
    href = d['href']
    csvfile = open('./91.csv', 'a', newline='')
    writer = csv.writer(csvfile)

    writer.writerow([index, title, long, date, collection, href])
    f.close()

write_header()
with open('./91list.txt', 'r') as f:
    lines = f.readlines()
for x in range(len(lines)):
    write_csv(x, lines)

